<?php

class Admin extends CI_Controller {

	var $page  = 'admin';
	var $action  = '';



	public function index(){

		$data = '';


		if(isset($_REQUEST['username'])&&isset($_REQUEST['password'])){
			$username  = $_REQUEST['username'];
			$password  = $_REQUEST['password'];
			$checkUser = $this->db->query("select * from users where  username = '$username' and password = '$password' and (usertype='A' or usertype='S') limit 1");



			if($checkUser->row() != null){
					
				$this->session->set_userdata('user_id', $checkUser->row()->id);
				$this->session->set_userdata('user_fullname', $checkUser->row()->firstname." ".$checkUser->row()->middlename." ".$checkUser->row()->lastname);
				$this->session->set_userdata('user_email', $checkUser->row()->email);
				$this->session->set_userdata('user_type', $checkUser->row()->usertype);

			}
			else{

			}
		}

		$data ='';
		$this->admin($data , null);

	}


	public function logout(){

		$this->session->unset_userdata('user_id');
		$this->session->unset_userdata('user_fullname');
		$this->session->unset_userdata('user_email');
		$this->session->unset_userdata('user_type');

		$data ='';
		$this->admin($data , null);
	}

}